package cn.sc.allinpay.allfavour.business.setpwd;

import android.content.DialogInterface;

import com.alibaba.fastjson.JSONObject;

import cn.pai.common.listener.OnPromptListener;
import cn.pai.mvp.callback.MpCallBack;
import cn.pai.mvp.presenter.PaiPresenter;
import cn.sc.allinpay.allfavour.business.common.data.CashierData;

/**
 * 登录密码修改 presenter
 * author：pany
 * on 2017/12/1 11:27
 */
public class SetPwdPresenter extends PaiPresenter<SetPwdContract.View> implements SetPwdContract.Presenter {

    private SetPwdModel model = new SetPwdModel();

    @Override
    public void start() {
        CashierData cashierData = model.getGlobal().getCashierData();
        view.showName("  " + cashierData.getCashierNo() + "  " + cashierData.getCashierName());
    }

    @Override
    public void reqLoginPwdModify() {
        String oriPwd = view.getOriPwd();
        String newPwd = view.getNewPwd();
        String cfmPwd = view.getCfmPwd();
        if (!newPwd.equals(cfmPwd)) {
            view.prompt("新密码与确认密码不一致");
            return;
        }
        view.loading();
        model.reqLoginPwdModify(oriPwd, cfmPwd, new MpCallBack<JSONObject, String>() {
            @Override
            public void onSuccess(JSONObject response) {
                view.loaded();
                view.prompt(false, "密码修改成功", new OnPromptListener("确定") {
                    @Override
                    public void onPositive(DialogInterface dialog, int which) {
                        view.finish();
                    }
                });
            }

            @Override
            public void onFailure(String response, String message) {
                view.loaded();
                view.prompt(message);
            }
        });
    }
}
